import dayJS from "dayjs";
import { defineStore } from 'pinia'
import { ElMessageBox, ElMessage } from "element-plus";

import { ref } from 'vue'
const useTeamStore = defineStore('team', () => {
    const teamList = ref([
        {
            avatarUrl: "blob:http://127.0.0.1:5173/df84e062-5dc1-4ac2-8acb-6e10dc1f3812",
            intro: "<p>少时诵诗书所所所所所所</p>",
            num: 521521,
            region: "是",
            time: "2022年11月09日",
            userjob: "经理",
            username: "张三",
            zip: 2
        }
    ])
    // 删除
    const removeTeamList = (id) => {
        // console.log(id)
        const res = teamList.value.findIndex((itme) => itme.num == id)
        teamList.value.splice(res,1)
    }
    // 添加
    const addTeamList = (obj) => {
        const res = teamList.value.find((itme) => itme.username == obj.username)
        if (res) {
            // res = JSON.parse(JSON.stringify(obj))
            res.avatarUrl = obj.avatarUrl
            res.intro = obj.intro
            res.num = obj.num
            res.region = obj.region
            res.userjob = obj.userjob
            ElMessage("修改成功");

        } else {
            teamList.value.push(obj)
            ElMessage("添加成功");

        }

    }
    // 利用id查找
    const filterTeamList = (num) => {
        const res = teamList.value.find((itme) => itme.num == num)
        return res
    }
    return {
        teamList,
        addTeamList,
        filterTeamList,
        removeTeamList
    }
}, {
    persist: true
})
export default useTeamStore